package com.yanqu.road.logic.activity.foxcard.game.buff;

import com.yanqu.road.entity.activity.foxcard.config.FoxCardMagicWeaponConfig;
import com.yanqu.road.entity.activity.foxcard.config.FoxCardSorceryConfig;
import com.yanqu.road.entity.activity.foxcard.config.FoxCardSpellConfig;
import com.yanqu.road.logic.activity.foxcard.FoxCardConfig;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardShowInfo;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardTriggerType;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardType;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;

/**
 * 本轮战斗结束时还在手中获得资源
 * 数量|cardtype|0|0|0|0
 */
public class FoxCardBuff10 extends FoxCardBuffBase{
    @Override
    protected boolean buffHandle(FoxCardGameLogic gameLogic) {
        if (triggerType != eFoxCardTriggerType.ROUND_END) {
            return false;
        }

        int cardNum = buffConfig.getParamsList().get(0);
        int cardType = buffConfig.getParamsList().get(1);

        FoxCardConfig config = gameLogic.getConfig();
        if (cardType == eFoxCardType.MAGIC_WEAPON.getValue()) {
            List<FoxCardMagicWeaponConfig> magicWeaponConfigs = config.randomMagicWeapons(cardNum, new HashSet<>());
            for (FoxCardMagicWeaponConfig magicWeaponConfig : magicWeaponConfigs) {
                if (gameLogic.getGameData().getConsumeCards().size() >= gameLogic.getGameData().getConsumeCardNumLimit()) {
                    break;
                }
                FoxCardShowInfo showInfo = gameLogic.addNewConsumeCard(cardType, magicWeaponConfig.getId(), 0);
                showInfo.setTriggerCards(Collections.singletonList(baseCard));
            }
        } else if (cardType == eFoxCardType.SPELL.getValue()) {
            List<FoxCardSpellConfig> spellConfigs = config.randomSpells(cardNum);
            for (FoxCardSpellConfig spellConfig : spellConfigs) {
                if (gameLogic.getGameData().getConsumeCards().size() >= gameLogic.getGameData().getConsumeCardNumLimit()) {
                    break;
                }
                FoxCardShowInfo showInfo = gameLogic.addNewConsumeCard(cardType, spellConfig.getId(), 0);
                showInfo.setTriggerCards(Collections.singletonList(baseCard));
            }
        } else if (cardType == eFoxCardType.SORCERY.getValue()) {
            List<FoxCardSorceryConfig> foxCardSorceryConfigs = config.randomSorceryList(cardNum);
            for (FoxCardSorceryConfig foxCardSorceryConfig : foxCardSorceryConfigs) {
                if (gameLogic.getGameData().getConsumeCards().size() >= gameLogic.getGameData().getConsumeCardNumLimit()) {
                    break;
                }
                FoxCardShowInfo showInfo = gameLogic.addNewConsumeCard(cardType, foxCardSorceryConfig.getId(), 0);
                showInfo.setTriggerCards(Collections.singletonList(baseCard));
            }
        }


        return true;
    }
}
